8931. All OK

 

Positive integer n is given. Count and print the message “OK” as shown in the example.

 

Input. One positive integer n (n ≤ 100).

 

Output. Print the text “OK” numbered n times.

 

Sample input

Sample output

3

1 OK

2 OK

3 OK

 

 

SOLUTION

loop

 

Algorithm analysis

Use a for loop. Print the line numbers and the text “OK”.

 

Algorithm realization

Read the input value of n.

 

scanf("%d", &n);

 

Print the numbered text “OKn times.

 

for (i = 1; i <= n; i++)

  printf("%d OK\n", i);

 

Java realization

 

import java.util.*;

 

class Main

{

  public static void main(String[] args)

  {

    Scanner con = new Scanner(System.in);

 

Read the input value of n.

 

    int n = con.nextInt();

 

Print the numbered text “OKn times.

 

    for(int i = 1; i <= n; i++)

      System.out.println(i + " OK");

    con.close();

  }

}

 

Python realization

Read the input value of n.

 

n = int(input())

 

Print the numbered text “OKn times.

 

for i in range(1,n+1):

  print(i,"OK")